package com.fish.admin.module.salesman.validator;


import com.fish.admin.module.salesman.validation.DataScope;
import com.fish.common.core.base.LoginAppUser;
import com.fish.common.core.context.UserContextManager;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;


/**
 * @author lindy
 * @Classname DataScopeValidator
 * @Description 数据权限访问判断
 * @Date 2023/12/10* 17:47
 * @Version V1.0
 */
public class DataScopeValidator implements ConstraintValidator<DataScope, Integer> {


    @Override
    public void initialize(DataScope annotation) {
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
       LoginAppUser loginAppUser = UserContextManager.getRequiredContext();
       if (loginAppUser.isTenant()) {
           return value == 1 || value == 2;
       }
        return true;
    }

}
